package com.szdvte.news.intercept;

import com.szdvte.news.bean.Users;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

@SuppressWarnings("serial")
public class LoginInterceptor implements Interceptor 
{

	@Override
	public void destroy() 
	{

	}

	@Override
	public void init() 
	{

	}

	@Override
	public String intercept(ActionInvocation invocation) throws Exception 
	{
		String action = invocation.getProxy().getActionName();
		String method = invocation.getProxy().getMethod();
		boolean flag = true;
		Users user = (Users) invocation.getInvocationContext().getSession().get("user");
		System.out.println(user);
		
		if (action.equals("newsAction") 
				|| action.equals("newsTypeAction")
				|| action.equals("userAction")
				|| action.equals("commentAction")
				|| action.equals("newsAddAction")
				|| action.equals("newsTypeAddAction")
				|| action.equals("userAddAction")) 
		{
			
			if (user == null) {
				if (method.equals("login")) {
					flag = true;
				}else{
					flag = false;
				}	
			}
		}
		
		if (flag) 
		{
			invocation.invoke();
		}
		return "index";
	}

}
